home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / AVL_TREE.C < prev    next >
C/C++ Source or Header  |  1992-08-20  |  2KB  |  53 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/AVL_Tree.h>
  14.  
  15. // CoolAVL_Tree -- Copy constructor
  16.  
  17. template <class Type>
  18. CoolAVL_Tree<Type>::CoolAVL_Tree(const CoolAVL_Tree<Type>& b)
  19.  : CoolBinary_Tree<Type>(b)
  20. {}                  
  21.  
  22. // CoolAVL_Tree -- Reference to CoolBinary_Tree (Copies BT, and make AVL out of it)
  23.  
  24. template <class Type>
  25. CoolAVL_Tree<Type>::CoolAVL_Tree(const CoolBinary_Tree<Type>& b)
  26.  : CoolBinary_Tree<Type>(b)
  27. {
  28.   this->balance();                 // Do an AVL balance on new tree
  29. }                  
  30.  
  31.  
  32. // ~CoolAVL_Tree -- Destructor (not inline because it's virtual)
  33. template <class Type>
  34. CoolAVL_Tree<Type>::~CoolAVL_Tree() {}
  35.  
  36. // balance  -- Rebalance an AVL tree, and then recalculate each node's
  37. //             balance (right subtree depth minus left subtree depth)
  38. // input:      None
  39. // Output:     None
  40.  
  41. template <class Type>
  42. void CoolAVL_Tree<Type>::balance () {
  43.   CoolBinary_Tree<Type>::balance();
  44.   CoolBase_Binary_Tree::calc_depth (this->get_root(), 0, TRUE);
  45. }
  46.  
  47.  
  48. template<class Type>
  49. ostream& operator<< (ostream& os, const CoolAVL_Tree<Type>& av) {
  50.   print_tree((CoolBinary_Node<Type>*)av.get_root(),os);
  51.   return os;
  52. }
  53.